package com.llsydn.graphics;

import android.graphics.Matrix;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import com.llsydn.hello.R;

/**
 * @author lilinshen
 * @title matrix测试
 * @description 请填写相关描述
 * @date 2018/10/11 9:36
 */
public class MatrixTestActivity extends AppCompatActivity {

    private EditText et_matrix_scale;
    private EditText et_matrix_rotate;
    private EditText et_matrix_translateX;//偏移量X
    private EditText et_matrix_translateY;//偏移量Y
    private ImageView iv_matrix_icon;
    private Matrix matrix;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_matrix_test);
        //初始化数据
        et_matrix_scale = (EditText) findViewById(R.id.et_matrix_scale);
        et_matrix_rotate = (EditText) findViewById(R.id.et_matrix_rotate);
        et_matrix_translateX = (EditText) findViewById(R.id.et_matrix_translateX);
        et_matrix_translateY = (EditText) findViewById(R.id.et_matrix_translateY);
        iv_matrix_icon = (ImageView) findViewById(R.id.iv_matrix_icon);
        matrix = new Matrix();
    }

    /**
     * 缩放 测试
     *
     * @param view
     */
    public void scaleBitmap(View view) {
        float scale = Float.parseFloat(et_matrix_scale.getText().toString());
        //保存缩放比例
        matrix.postScale(scale, scale);
        //将matrix设置到imageView
        iv_matrix_icon.setImageMatrix(matrix);
    }

    /**
     * 旋转 测试
     *
     * @param view
     */
    public void rotateBitmap(View view) {
        float degree = Float.parseFloat(et_matrix_rotate.getText().toString());
        //保存旋转角度
        matrix.postRotate(degree);
        //将matrix设置到imageView
        iv_matrix_icon.setImageMatrix(matrix);
    }

    /**
     * 平移 测试
     *
     * @param view
     */
    public void translateBitmap(View view) {
        float dx = Float.parseFloat(et_matrix_translateX.getText().toString());
        float dy = Float.parseFloat(et_matrix_translateY.getText().toString());
        //保存平移数据
        matrix.postTranslate(dx, dy);
        //将matrix设置到imageView
        iv_matrix_icon.setImageMatrix(matrix);
    }

    /**
     * 还原 测试
     *
     * @param view
     */
    public void clearMatrix(View view) {
        matrix.reset();
        //将matrix设置到imageView
        iv_matrix_icon.setImageMatrix(matrix);
    }

}
